
const db = require("./db");
const config = require('../config');
const md5 = require("./md5");

/**
 * 检查secret_id是否与user_id匹配，或secret_id具有管理员权限
 * 魔改为同步执行
 * @param {*} secret_id 
 * @param {*} user_id 
 */
async function checkauth(secret_id, user_id) {
    try {
        var u = md5.hexMD6(secret_id);
        var auth = (await db.query(`Select authority from user where user_id = '${u}'`))[0].authority;
        return auth == 10 || (u == user_id && auth == 5);
    } catch (e) {
        return false;
    }
}

module.exports = {
    checkauth: checkauth
}
